<?php

namespace beObject\Web\Mail;

use beObject\Object;
use beObject\Primitive\Boolean;
use beObject\Primitive\String;

  class MailMessage extends Object {

    /** @var String The recipient(s) of the email. */
    protected $recipient = "";

    /** @var String The recipient(s) in copy. */
    protected $cc = "";

    /** @var String The recipient(s) in hidden copy. */
    protected $bcc = "";

    /** @var String The address for reply. */
    protected $reply = "";

    /** @var String The sender address. */
    protected $sender = "";

    /** @var String The sender name to display. */
    protected $sender_name = "";

    /** @var String The subject of the email. */
    protected $subject = "";

    /** @var String The body of the email. */
    protected $body = "";

    /** @var Boolean Define if the content is in HTML format. */
    protected $html = false;

    /** @var array Collection of attachment files. */
    public $attachments = array();

    /**
     * Store all parameter in private.
     * @param String $recipient The recepient
     * @param String $sender The sender
     * @param String $subject The subject
     * @param String $body The body
     * @param Boolean $HTML Set to True if the body is in HTML format
     */
    public function __construct(String $recipient = null, String $sender = null, String $subject = null, String $body = null, Boolean $html = null) {
      $this->recipient = $recipient != null ? $recipient : new String();
      $this->sender = $sender != null ? $sender : new String();
      $this->subject = $subject != null ? $subject : new String();
      $this->body = $body != null ? $body : new String();
      $this->html = $html != null ? $html : new Boolean(false);
    }

    /**
     * Returns the attachments.
     * @return array The attachments.
     */
    public function getAttachments() {
      return $this->attachments;
    }

    /**
     * Returns the recipient.
     * @return String The recipient.
     */
    public function getRecipient() {
      return $this->recipient;
    }

    /**
     * Returns the copy recipient.
     * @return String The copy recipient.
     */
    public function getCopy() {
      return $this->cc;
    }

    /**
     * Returns the hidden copy recipient.
     * @return String The hidden copy recipient.
     */
    public function getHiddenCopy() {
      return $this->bcc;
    }

    /**
     * Returns the address for reply.
     * @return String The address for reply.
     */
    public function getReply() {
      return $this->reply;
    }

    /**
     * Returns the sender.
     * @return String The sender.
     */
    public function getSender() {
      return $this->sender;
    }

    /**
     * Returns the sender name to display.
     * @return String The sender name.
     */
    public function getSenderName() {
      return $this->sender_name;
    }

    /**
     * Returns the subject.
     * @return String The subject.
     */
    public function getSubject() {
      return $this->subject;
    }

    /**
     * Returns the body.
     * @return String The body.
     */
    public function getBody() {
      return $this->body;
    }

    /**
     * Define if the email content is in HTML format.
     * @return Boolean TRUE if the content is in HTML format.
     */
    public function isHtml() {
      return $this->html;
    }

    /**
     * Set the recipient.
     * @param string $value The recipient.
     */
    public function setRecipient($value) {
      $this->recipient = new String($value);
    }

    /**
     * Sets the copy recipient.
     * @param string $value The copy recipient.
     */
    public function setCopy($value) {
      $this->cc = new String($value);
    }

    /**
     * Sets the hidden copy recipient.
     * @param string $value The hidden copy recipient.
     */
    public function setHiddenCopy($value) {
      $this->bcc = new String($value);
    }

    /**
     * Sets the address for reply.
     * @param string $value The address for reply.
     */
    public function setReply($value) {
      $this->reply = new String($value);
    }

    /**
     * Set the sender.
     * @param string $value The sender.
     */
    public function setSender($value) {
      $this->sender = new String($value);
    }

    /**
     * Sets the sender name to display.
     * @param string $value The sender name.
     */
    public function setSenderName($value) {
      $this->sender_name = new String($value);
    }

    /**
     * Set the subject.
     * @param string $value The subject.
     */
    public function setSubject($value) {
      $this->subject = new String($value);
    }

    /**
     * Set the body.
     * @param string $value The body.
     */
    public function setBody($value) {
      $this->body = new String($value);
    }

    /**
     * Sets the email content to HTML format, or not.
     * @param boolean True for HTML format, false otherwise.
     */
    public function setToHtml($value = true) {
      $this->html = Boolean::parseBoolean($value);
    }

    /**
     * Attach a file to the mail to send.
     * @param MailAttachment $MailAttachment A file to attach to the mail.
     * @link http://be2.php.net/manual/en/function.is-a.php
     * @link http://be2.php.net/manual/en/function.array-push.php
     */
    public function attach(MailAttachment $attachment) {
      $this->attachments[] = $attachment;
    }

  }

?>
